﻿import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Dialogs 1.2

Dialog {
    id: networkConfigDialog
    width: 600
    height: 480
    title: "网络配置"
    modality: Qt.WindowModal

    ListModel{
        id: listmodel
        ListElement{text: "default_1"}
    }

    function setCombox(var1, var2, var3){
        listmodel.clear()
        listmodel.append({text: var1})
        if(var2.length > 0)
            listmodel.append({text: var2})
        if(var3.length > 0)
            listmodel.append({text: var3})
        comboBox.currentIndex = 0
    }

    function clearPingTestLog(){
        textArea.clear()
    }

    function appendPingTestLog(var1){
        textArea.append(var1)
    }

    contentItem: Rectangle{
        id: root_window
        width: networkConfigDialog.width
        height: networkConfigDialog.height

        ComboBox {
            id: comboBox
            model: listmodel
            x: 20
            y: 77
            width: root_window.width*0.7
            height: 40
        }

        TextField {
            id: textField
            height: 40
            width: 110
            x: root_window.width - 130
            y: 77
            text: qsTr("本机网卡选择")
        }

        TextField {
            id: ipAddress
            x: 20
            y: 153
            width: root_window.width*0.7
            height: 40
            text: qsTr("192.168.1.")
        }

        Button {
            id: button_ping
            x: root_window.width - 130
            y: 153
            height: 40
            width: 110
            text: qsTr("PING")

            onClicked: {
                systimer.pingTest(ipAddress.text)
            }
        }

        Button {
            id: button
            x: 364
            y: root_window.height - 60
            width: 100
            height: 40
            text: qsTr("确定")

            onClicked: {
                valuesource.localIP = comboBox.currentText
                systimer.setLocalIPAddress(valuesource.localIP)
                networkConfigDialog.close()
            }
        }

        TextArea {
            id: textArea
            x: 20
            y: 216
            width: root_window.width - 40
            height: root_window.height * 0.4
            text: ""
            background: Rectangle{
                width: parent.width
                height: parent.height
                color: "#aaaaaa"
            }
        }

        Switch {
            id: element
            x: 20
            y: root_window.height - 60
            checked: true
            text: qsTr("测试完成后自动关机（下位机端）")

            onToggled: {
                switch_poweroffAuto.checked = element.checked
            }
        }
    }
}
